package com.ljh.tr.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class BaseDao {
	
	private static final String URL = "jdbc:mysql://127.0.0.1:3306/Tech2Real?characterEncoding=utf-8";
	private static final String USER = "root";
	private static final String PASSWORD = "root";
	private static final String DRIVER = "com.mysql.jdbc.Driver";
	
	/**
	 * @return connection 连接数据库对象
	 */
	public static Connection getCon(){
		Connection conn =null;
		try {
			Class.forName(DRIVER);
			conn =DriverManager.getConnection(URL, USER, PASSWORD);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}
	
	/**
	 * @param conn 数据库连接类
	 * @param ps 回话
	 * @param rs 结果集
	 */
	public static void closeAll(Connection conn , PreparedStatement ps,ResultSet rs){
		if(null != conn){
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		if(null != ps){
			try {
				ps.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(null != rs){
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}
